Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
countup.js
Advanced tools
countup.js is a lightweight JavaScript library that allows you to create animated counting numbers. It is useful for creating dynamic and engaging number displays in web applications, such as statistics, counters, and other numerical data visualizations.
Basic Count Up
This feature allows you to animate a number counting up from zero to a specified value. In this example, the number will count up to 1000 and display in the element with the ID 'targetElement'.
const countUp = new CountUp('targetElement', 1000);
if (!countUp.error) {
countUp.start();
} else {
console.error(countUp.error);
}
Custom Start and End Values
This feature allows you to specify custom start and end values for the count up animation. In this example, the number will count up from 500 to 2000.
const countUp = new CountUp('targetElement', 2000, { startVal: 500 });
if (!countUp.error) {
countUp.start();
} else {
console.error(countUp.error);
}
Formatting Options
This feature allows you to format the number with options such as decimal places, prefixes, and suffixes. In this example, the number will be formatted with two decimal places and display as currency (e.g., $1000.00 USD).
const countUp = new CountUp('targetElement', 1000, { decimalPlaces: 2, prefix: '$', suffix: ' USD' });
if (!countUp.error) {
countUp.start();
} else {
console.error(countUp.error);
}
Easing Functions
This feature allows you to apply custom easing functions to the count up animation. In this example, a quadratic easing function is used to create a smooth animation effect.
const countUp = new CountUp('targetElement', 1000, { easingFn: function (t, b, c, d) { return c * (t /= d) * t + b; } });
if (!countUp.error) {
countUp.start();
} else {
console.error(countUp.error);
}
Odometer is a smooth, themeable, and easy-to-use JavaScript library for transitioning numbers. It provides a more visually appealing way to animate numbers compared to countup.js, with various themes and styles that mimic the look of an odometer.
jquery.counterup is a jQuery plugin that animates a number from zero to a specified value. It is similar to countup.js but requires jQuery as a dependency, making it less lightweight. It is suitable for projects that already use jQuery.
CountUp.js is a dependency-free, lightweight JavaScript "class" that can be used to quickly create animations that display numerical data in a more interesting way.
Despite its name, CountUp can count in either direction, depending on the startVal
and endVal
params that you pass.
CountUp.js supports all browsers.
Angular 1 and 2 modules used to be part of this repo. As of v1.9.0, they have moved. See links below.
Simply include the countUp.js file in your project or install via npm or bower using the package name countup.js
or countUp.js
respectively.
Before making a pull request, please read this. MIT License.
A jQuery version is also included in case you like dollar signs.
Params:
target
= id of html element, input, svg text element, or var of previously selected element/input where counting occursstartVal
= the value you want to begin atendVal
= the value you want to arrive atdecimals
= (optional) number of decimal places in number, default 0duration
= (optional) duration in seconds, default 2options
= (optional, see demo) formatting/easing options objectDecimals, duration, and options can be left out to use the default values.
var numAnim = new CountUp("SomeElementYouWantToAnimate", 24.02, 99.99);
if (!numAnim.error) {
numAnim.start();
} else {
console.error(numAnim.error);
}
with optional callback:
numAnim.start(someMethodToCallOnComplete);
// or an anonymous function
numAnim.start(function() {
// do something
})
Toggle pause/resume:
numAnim.pauseResume();
Reset an animation:
numAnim.reset();
Update the end value and animate:
var someValue = 1337;
numAnim.update(someValue);
For large numbers, since CountUp has a long way to go in just a few seconds, the animation seems to abruptly stop. The solution is to subtract 100 from your endVal
, then use the callback to invoke the update
method which completes the animation with the same duration with a difference of only 100 to animate:
var endVal = 9645.72;
var numAnim = new CountUp("targetElem", 0, endVal - 100, 2, duration/2);
numAnim.start(function() {
numAnim.update(endVal);
});
Before you make a pull request, please be sure to follow these super simple instructions:
countUp.js
and/or other files in the root directory.cd
to the countUp.js
directory.npm install
, which installs gulp and its dependencies.gulp
, which copies and minifies the .js files to the dist
folder.FAQs
Animates a numerical value by counting to it
The npm package countup.js receives a total of 369,759 weekly downloads. As such, countup.js popularity was classified as popular.
We found that countup.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.